<?php

class UploadComponent extends Object {

    var $name = 'Upload';

    function ImagesOnly($array_files,$max_size){
        $errno = 0;
        foreach($array_files as $f){
            $type = $f['type'];
            if($type!='image/png' && $type!='image/jpg' && $type!='image/gif'){
                $errno = 1;
                break;
            }
            if(size > $max_size){
                $errno = 2;
                break;
            }
        }
        return $errno;
    }

    function upload($files,$folder) {
        $errno = 0;
        foreach($files as $f){
            $type = $f['type'];
            if($type!='image/png' && $type!='image/jpg' && $type!='image/gif'){
                $errno = 1;
                break;
            }
            if(size > 200000){
                $errno = 2;
                break;
            }
        }
        if($errno==0){
            foreach($files as $f){
                if(!move_uploaded_file($filename, $this->webroot+'')){
                    $errno=3;
                }
            }
        }
        return $errno;
    }

}

?>
